<?php

if (!defined('_PAGE_'))
    include _FLEP_LIB_DIR_.'/page.inc';

$css = array('jquery-ui.css', 'add_estudiante.css');
$javascript = array('add_common.js', 'add_pago.js');

flep_structure($structure, 'inscripcion');

if(isset($_POST['id']) && $_POST['cid']){
    $structure['where'][0] = sprintf("`inscripciones`.`id`='%s'", flep_decode($_POST['id']));
} else {
    header('Location: main.php?page=curso');
}

function include_page($structure){
    $user = &$_SESSION['user'];
    $structure['alias'][0] = '*';
    $structure['alias'][1] = '`estudiantes`.`nombre`AS nombre';
    $structure['alias'][2] = '`estudiantes`.`usuario` AS usuario';
    $structure['alias'][3] = '`docentes`.`nombre`AS docente';
    flep_search_all($structure);
    flep_structure($pagos, 'pago');
    $pagos['where'][0] = 'inscripcion_id='.$structure['data'][0]['id'];
    $edit = flep_search_all($pagos);
?><br>
    <table class="header2">
        <tbody>
            <tr><th colspan="4"><b>&nbsp;<?php echo $structure['data'][0]['categoria']; ?></b></th></tr>
            <tr><th colspan="4"><img src="img/<?php echo $structure['data'][0]['activo']?'ok':'close'; ?>.png"><b><?php echo strtoupper($structure['data'][0]['usuario']); ?> - <?php echo $structure['data'][0]['nombre']; ?></b></th></tr>
            <tr><td colspan="4">&nbsp;</td></tr>
            <tr><th colspan="4"><b>Nivel <?php echo $structure['data'][0]['nivel']; ?> - <?php echo $structure['data'][0]['docente']; ?></b></th></tr>
            <tr><th>Fecha de Inicio:</th><td><?php echo $structure['data'][0]['fecha_inicio']; ?></td><th>Horario:</th><td><?php echo $structure['data'][0]['horario']; ?></td></tr>
            <tr><th>fecha de Cierre:</th><td><?php echo $structure['data'][0]['fecha_cierre']; ?></td><th>Idioma:</th><td><?php echo $structure['data'][0]['idioma']; ?></td></tr>
        </tbody>
    </table>
    <br>
    <b>Pago:</b>
    <br>
    <p class="error" id="perror"></p>
    <form action="store.php?type=pago&page=detalle_curso&search=id:<?php echo $_POST['cid']; ?>" method="POST" id="form_pago" name="form_pago">
    <input type="hidden" value="<?php echo ($edit?flep_encode($pagos['data'][0]['id']):'')?>" id="id" name="id">
    <input type="hidden" value="<?php echo flep_encode($structure['data'][0]['id'])?>" id="inscripcion_id" name="inscripcion_id">
        <table>
           <tr>
           <tr>
                <td><label>N&deg; de Recibo:</label></td>
                <td><input type="text" autofocus name="recibo" style="width: 250px" value="<?php echo ($edit?$pagos['data'][0]['recibo']:'')?>" required placeholder="N&deg; de Recibo"></td>
            </tr>
            <tr>
                <td><label>Monto:</label></td>
                <td><input type="text" name="cantidad" style="width: 100px" autocomplete="off" value="<?php echo ($edit?sprintf('%01.2f', $pagos['data'][0]['cantidad']):'')?>" required placeholder="Cantidad"></td>
            </tr>
            <tr>
                <td><label>Fecha de Pago:</label></td>
                <td><input type="text" name="fecha_pago" id="fecha_pago" style="width: 200px" value="<?php echo ($edit?$pagos['data'][0]['fecha_pago']:'')?>" placeholder="Formato: YYYY-MM-DD" ></td>
            </tr>
            <tr>
                <td><label>Exonerado:</label></td>
                <td><input type="hidden" name="exonerado" value="0"><input type="checkbox" name="exonerado" value="1" <?php echo ($edit && $pagos['data'][0]['exonerado'] === '1'? 'checked' :'')?>></td>
            </tr>
            <tr>
                <td><label onclick="flep_show_comment('textarea_pago');" title="Click para mostrar/ocultar">Comentarios:</label></td>
                <td><textarea style="display: none;" form="form_pago" name="comentario" id="textarea_pago"><?php echo ($edit?$pagos['data'][0]['comentario']:'')?></textarea></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" value="Guardar" style="margin-right: 100px;"><input type="reset" value="Restablecer"></td>
            </tr>
        </table>
    </form>
<?php
}
?>
